# sql = "SELECT * FROM user WHERE INCOME > %s" % (1000) sql = "SELECT * FROM user WHERE INCOME > %s" try: cursor.execute(sql, (1000,)) # 执行SQL语句,在第二个参数中传参(把所有参数放在一个元组中) except Exception as e: print(f"SQL执行失败:{e}")
#方法二: mysql中: use db1; SET SQL_LOG_BIN=0; #关闭二进制日志,只对当前session生效 source /root/db1.sql
(左右滑动查看完整内容)
事务和锁
begin; # 开启事务 select * from user where NAME = 'pamela'for update; # 查询,for update添加行级锁(select语句后面加一个for update) update user set INCOME=10000 where NAME = 'pamela'; # 完成更新 commit; # 提交事务,释放行级锁